package com.whcoding.mybatis.controller;

import com.whcoding.mybatis.pojo.OrmDeptVO;
import com.whcoding.mybatis.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Sanilthink
 *
 */
@RestController
@RequestMapping("/dept/")
public class DeptController {

    @Autowired
    private DeptService deptService;

	/**
	 * 新增数据
	 * @param deptVO
	 * @return
	 */
    @PostMapping("add")
    public boolean addDept(@RequestBody OrmDeptVO deptVO) {
        return deptService.addDept(deptVO);
    }

    /**
     *
     * @param id
     * @return
     */
    @GetMapping("queryDeptById")
    public OrmDeptVO queryDeptById(@RequestParam("id")  Long id) {
        return deptService.queryDeptById(id);
    }

	/**
	 * 查询全部数据
	 * @return
	 */
    @GetMapping("queryAllDept")
    public List<OrmDeptVO> queryAllDept() {
        return deptService.queryAllDept();
    }



	/**
	 * ResponseEntity
	 * return ResponseEntity.ok().build();
	 *
	 * @param deptType
	 * @return
	 */
	@GetMapping("/queryMaxDeptId")
	public ResponseEntity queryDeptId(@RequestParam("deptType") Integer deptType) {
		Integer maxDeptId = deptService.findMaxDeptId(deptType);
		return ResponseEntity.ok(maxDeptId);
	}

	/**
	 * deptList
	 * @return
	 */
	@GetMapping("/listDept")
	public ResponseEntity listDept() {
		List<OrmDeptVO> deptVOList = deptService.queryAllDept();
		return ResponseEntity.ok(deptVOList);
	}

}
